<template>
  <div class="app-container">


    <el-form :model="searchForm" size="small" :inline="true"   label-width="68px">
      <el-form-item label="病历号" prop="registId">
        <el-input v-model="searchForm.registId"   placeholder="请输入病历号"   clearable    />
      </el-form-item>

      <el-form-item label="姓名" prop="name">
        <el-input  v-model="searchForm.name"  placeholder="请输入患者姓名"   clearable    />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="加载中..."
      border
      fit
      highlight-current-row
      size="mini"
    >
      <el-table-column align="center" type="index" label="序号" width="95">  </el-table-column>
<!--      <el-table-column align="center" prop="checkId" label="checkId" width="95">  </el-table-column>-->
      <el-table-column align="center" prop="registId" label="病例号">  </el-table-column>
      <el-table-column align="center" prop="name" label="患者姓名">  </el-table-column>
      <el-table-column align="center" prop="gender" label="性别"  >  </el-table-column>
      <el-table-column align="center" prop="age" label="年龄"  >  </el-table-column>
      <el-table-column align="center" prop="deptId" label="挂号科室"  >  </el-table-column>
      <el-table-column align="center" prop="visitTime" label="看诊时间"  >  </el-table-column>
      <el-table-column  label="状态"  >

            <template slot-scope="scope">
              <el-tag v-if="scope.row.status == 1">
                    待看诊
              </el-tag>
              <el-tag v-else-if="scope.row.status == 2" type="success">
                已接诊
              </el-tag>
              <el-tag v-else-if="scope.row.status == 3" type="danger">
                退号
              </el-tag>
            </template>

      </el-table-column>
      <el-table-column align="center" prop="fee" label="挂号费"  >  </el-table-column>
      <el-table-column align="center"  label="操作"  >
        <template slot-scope="scope">

                <el-button size="mini" v-if="scope.row.status == 1 " type="primary" @click="handlerRefundNumber(scope.row.registId)">退号</el-button>
        </template>

      </el-table-column>
    </el-table>


    <el-pagination
      background
      @current-change="fetchData()"
      layout="prev, pager, next,sizes"
      :page-sizes="[5, 10, 20, 50]"
      :current-page.sync="searchForm.pageNo"
      :page-size.sync="searchForm.size"
      :total="searchForm.total">
    </el-pagination>

  </div>
</template>

<script>
import { getList,handlerRefundNumber  } from '@/api/regist/regist'
export default {
  data() {
    return {

      searchForm:{
        pageNo:1,
        size:10,
        total:0,
        registId:'',
        name:'',
      },
      list: null,
      listLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    search(){
      this.fetchData()
    },

    fetchData() {
      this.listLoading = true
      let param = {
        pageNo:this.searchForm.pageNo,
        size:this.searchForm.size,
        registId:this.searchForm.registId,
        name:this.searchForm.name
      }

      getList(param).then(page => {
         this.list = page.data;

        let {total ,pages,size,pageNo} = page;
        this.searchForm.total = total

        this.listLoading = false
      })
    },
    handlerRefundNumber(registId){
              this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确认退号',
                cancelButtonText: '取消',
                  type: 'warning'
              }).then(() => {
                handlerRefundNumber(registId).then(res=>{
                  if(res){
                    this.$message.success("退号成功");
                    this.search();
                  }else{
                    this.$message.warning("退号失败!!!!!");
                  }
                })
              })






    }

  }
}
</script>
